package com.vinfai.common.util;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

public class DAOUtil {
	private static Logger logger = Logger.getLogger(DAOUtil.class);
	/**
	 * 根据SQL语句生成查询数量SQL
	 * @param sql
	 * @return
	 */
	public String convertToCountSql(String sql){
		//select子句与order by子句会影响count查询
		String orgSql = sql;
		orgSql = "from "+ StringUtils.substringAfter(orgSql.toLowerCase(), "from");
		orgSql = StringUtils.substringBefore(orgSql, "order by");
		return "SELECT COUNT(*) "+orgSql;
	}
	
}
